/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Formas.Maquinas;

import Formas.InterMaquinas;
import datos.*;
import java.awt.Image;
import java.awt.event.ItemEvent;
import java.awt.event.KeyEvent;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author lupiss
 */
public class FormLil extends javax.swing.JFrame {

    private BDAdmin objCon = new BDAdmin();
    public tratadatos objDatos = new tratadatos();
    private FileInputStream fis;
    private int longitudBytes;
    private ControllerMaquina cc1;

    /**
     * Creates new form FormLil
     */
    public FormLil() {
        initComponents();
        this.setLocationRelativeTo(null);
        llenarCombomaquinas();
        cc1 = new ControllerMaquina();
        jC_maquinasBuscar.setSelectedItem(ServerBridge.getnombreMaquina());
        //cargaImagendefault(ServerBridge.getnombreMaquina());
        jL_clavelil.setText("AML_" + objDatos.getCadenaAlfanumAleatoria(8));
        if (ServerBridge.gettipoLil().equals("Maquina")) {
            jL_tipolil.setText("Maquina");
            jL_Maquina.setText(ServerBridge.getnombreMaquina());
            jC_categoria.setEnabled(true);
            jT_punto.setText(cargaPuntodeinspeccion(idmaquina(String.valueOf(jC_maquinasBuscar.getSelectedItem()))));

        } else {
            jC_categoria.setEnabled(false);
            jL_tipolil.setText("Componente");
            jL_Maquina.setText(ServerBridge.getnombreMaquina());
            jL_componente.setText(ServerBridge.getnombreComponente());
            jT_punto.setText(cargaPuntodeinspeccionComponente(
                    idcomponente(idmaquina(String.valueOf(jC_maquinasBuscar.getSelectedItem())), jL_componente.getText())));
            System.out.println(idmaquina(String.valueOf(jC_maquinasBuscar.getSelectedItem()))+" "+ jL_componente.getText());

        }
        jL_fecha.setText(ServerBridge.getfechasistemacompleta());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jL_fecha = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jC_runstop = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jT_punto = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        lb_foto = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTA_estandar = new javax.swing.JTextArea();
        jLabel10 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jCheck_manual = new javax.swing.JCheckBox();
        jCheck_visual = new javax.swing.JCheckBox();
        jCheck_auditivo = new javax.swing.JCheckBox();
        jCheck_olfato = new javax.swing.JCheckBox();
        jPanel6 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable_herramientas = new javax.swing.JTable();
        jC_herramientas = new javax.swing.JComboBox();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTA_accion = new javax.swing.JTextArea();
        jLabel17 = new javax.swing.JLabel();
        jT_tiempo = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jC_frecuencia = new javax.swing.JComboBox();
        jLabel21 = new javax.swing.JLabel();
        jL_clavelil = new javax.swing.JLabel();
        jTA_componente = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        jC_categoria = new javax.swing.JComboBox();
        jLabel22 = new javax.swing.JLabel();
        jC_prioridad = new javax.swing.JComboBox();
        jLabel23 = new javax.swing.JLabel();
        jL_tipolil = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        jL_Maquina = new javax.swing.JLabel();
        jLabel26 = new javax.swing.JLabel();
        jL_componente = new javax.swing.JLabel();
        jB_addlil = new javax.swing.JButton();
        jB_uplil = new javax.swing.JButton();
        jB_dellil = new javax.swing.JButton();
        jB_cleanlil = new javax.swing.JButton();
        jC_maquinasBuscar = new javax.swing.JComboBox();
        jChe_activa = new javax.swing.JCheckBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setUndecorated(true);

        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("LIL (Limpieza, Inspección y Lubricación)");

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));

        jButton1.setText("SALIR");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel2.setText("Maquina:");

        jLabel4.setText("Fecha:");

        jL_fecha.setText(".");

        jLabel5.setText("Run / Stop:");

        jC_runstop.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "R = Run", "S = Stop" }));

        jLabel7.setText("Punto de Inspección:");

        jT_punto.setEditable(false);

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        lb_foto.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lb_fotoMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lb_foto, javax.swing.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lb_foto, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE)
                .addContainerGap())
        );

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText("DIAGRAMA DE MAQUINA");

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel6.setText("Caracteristicas de LIL");

        jLabel8.setText("Componente:");

        jLabel9.setText("Estandar de Inspección:");

        jTA_estandar.setColumns(20);
        jTA_estandar.setRows(5);
        jScrollPane2.setViewportView(jTA_estandar);

        jLabel10.setText("Metodo:");

        jPanel5.setBackground(new java.awt.Color(255, 255, 255));

        jLabel11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/Imagen1.png"))); // NOI18N

        jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/Imagen2.png"))); // NOI18N

        jLabel13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/Imagen3.png"))); // NOI18N

        jLabel14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/Imagen4.png"))); // NOI18N

        jCheck_manual.setText("Manual");

        jCheck_visual.setText("Visual");
        jCheck_visual.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheck_visualActionPerformed(evt);
            }
        });

        jCheck_auditivo.setText("Auditivo");

        jCheck_olfato.setText("Olfato");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel11)
                            .addComponent(jLabel12))
                        .addGap(11, 11, 11)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jCheck_visual, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jCheck_manual, javax.swing.GroupLayout.DEFAULT_SIZE, 65, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel13)
                            .addComponent(jLabel14))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jCheck_olfato, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jCheck_auditivo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jCheck_manual)
                    .addComponent(jLabel11))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCheck_visual))
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel13)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel14))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(15, 15, 15)
                        .addComponent(jCheck_auditivo)
                        .addGap(18, 18, 18)
                        .addComponent(jCheck_olfato)))
                .addContainerGap(10, Short.MAX_VALUE))
        );

        jPanel6.setBackground(new java.awt.Color(255, 255, 255));

        jTable_herramientas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Herramienta"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane3.setViewportView(jTable_herramientas);

        jC_herramientas.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Trapo", "Llave Allen", "Llave Mixta", "Brocha", "Cronómetro", "Nivel", "Probe", "Martillo", "Termómetro", "Regla", "Tacómetro", "Micrómetro", "Vernier", "Aceitera", "Bomba de grasa", "Uña de operación", "Custom Tool #2", "Gauge de lainas", "Manómetro", "Lainas", "Aspiradores", "Esponja", "Cincel", "Espátula", "Cepillo de alambre", "Plumero", "Cincha", "Desarmador" }));
        jC_herramientas.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jC_herramientasItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addComponent(jC_herramientas, 0, 249, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jC_herramientas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jLabel15.setText("Herramientas:");

        jLabel16.setText("Acción en caso de Anormalidad:");

        jTA_accion.setColumns(20);
        jTA_accion.setRows(5);
        jScrollPane4.setViewportView(jTA_accion);

        jLabel17.setText("Tiempo (Min.) ");

        jLabel18.setText("mins.");

        jLabel19.setText("Frecuencia:");

        jC_frecuencia.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "D = Diario", "S = Semanal", "Q = Quincenal", "M = Mensual", "B = Bimestral", "T = Trimestral", "Se = Semestral", "A = Anual" }));

        jLabel21.setText("Clave LILI:");

        jL_clavelil.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jL_clavelil.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jL_clavelil.setText(".");

        jLabel20.setText("Categoria:");

        jC_categoria.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Sistema Neumatico", "Transmisión Mecanica", "Energia Electrica", "Hidraulica" }));

        jLabel22.setText("Prioridad:");

        jC_prioridad.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Alta", "Media", "Baja" }));

        jLabel23.setText("Tipo LILI:");

        jL_tipolil.setText(".");

        jLabel24.setText("Maquina:");

        jL_Maquina.setText(".");

        jLabel26.setText("Componente:");

        jL_componente.setText(".");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addGap(233, 233, 233)
                                .addComponent(jLabel9))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jTA_componente)
                                    .addComponent(jLabel20)
                                    .addComponent(jC_categoria, 0, 273, Short.MAX_VALUE)
                                    .addComponent(jLabel22)
                                    .addComponent(jC_prioridad, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addComponent(jScrollPane2))))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel15, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(72, 72, 72)
                                .addComponent(jLabel17)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGap(9, 9, 9)
                                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jL_Maquina, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addGroup(jPanel4Layout.createSequentialGroup()
                                        .addComponent(jLabel23)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jL_tipolil, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addGroup(jPanel4Layout.createSequentialGroup()
                                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel19)
                                            .addGroup(jPanel4Layout.createSequentialGroup()
                                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                    .addComponent(jC_frecuencia, 0, 122, Short.MAX_VALUE)
                                                    .addComponent(jT_tiempo)
                                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                                                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                            .addComponent(jLabel24)
                                                            .addComponent(jLabel26))
                                                        .addGap(0, 0, Short.MAX_VALUE)))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(jLabel18))
                                            .addComponent(jL_componente, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(0, 0, Short.MAX_VALUE))))))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 298, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jC_runstop, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jT_punto, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel21)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jL_clavelil, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6)
                .addGap(14, 14, 14)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jC_runstop, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(jT_punto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel21)
                    .addComponent(jL_clavelil))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jTA_componente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel20)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jC_categoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel22)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jC_prioridad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel15)
                        .addComponent(jLabel16)
                        .addComponent(jLabel17)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane4)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jT_tiempo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel18))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel19)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jC_frecuencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel23)
                            .addComponent(jL_tipolil))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel24)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jL_Maquina)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel26)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jL_componente)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jB_addlil.setText("Agregar LIL");
        jB_addlil.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jB_addlilActionPerformed(evt);
            }
        });

        jB_uplil.setText("Modificar LIL");
        jB_uplil.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jB_uplilActionPerformed(evt);
            }
        });

        jB_dellil.setText("Eliminar LIL");

        jB_cleanlil.setText("Limpiar LIL");

        jC_maquinasBuscar.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jC_maquinasBuscar.setEnabled(false);
        jC_maquinasBuscar.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jC_maquinasBuscarItemStateChanged(evt);
            }
        });

        jChe_activa.setBackground(new java.awt.Color(255, 255, 255));
        jChe_activa.setText("Activar Maquinas");
        jChe_activa.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jChe_activaMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jC_maquinasBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 448, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jChe_activa, javax.swing.GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jL_fecha, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(38, 38, 38)
                        .addComponent(jButton1))
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jB_addlil)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jB_uplil, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jB_dellil, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jB_cleanlil, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jB_addlil)
                    .addComponent(jB_uplil)
                    .addComponent(jB_dellil)
                    .addComponent(jB_cleanlil))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(jLabel4)
                        .addComponent(jL_fecha)
                        .addComponent(jC_maquinasBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jChe_activa)))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void limpiatablaherraminetas() {
        DefaultTableModel temp1 = (DefaultTableModel) jTable_herramientas.getModel();
        for (int i = jTable_herramientas.getRowCount() - 1; i >= 0; i--) {
            temp1.removeRow(i);
        }
    }
    
    public String idusuario(){
        String valor="";
        String query = "select idusuarios from usuarios where cveusuario='" + ServerBridge.getidentificadorUsuario() + "' ";
        System.out.println(query);
        String tipo = objCon.consultar(query, ServerBridge.getusuBD(), ServerBridge.getpasBD());
        String[] dat = tipo.split(",");
        if(dat[0].equals("")||dat[0].equals("null")){
        JOptionPane.showMessageDialog(this,"No existe usuario de esta maquina");
        }else{
        valor=dat[0];
        }
        return valor;
    }
    
    public String idmaquina(String dato) {
        String query = "select idmaquinas from maquinas where nombre_compuesto='" + dato + "' and id_usuario='"+idusuario()+"'";
        System.out.println(query);
        String tipo = objCon.consultar(query, ServerBridge.getusuBD(), ServerBridge.getpasBD());
        String[] dat = tipo.split(",");
        if (dat[0].equals("") || dat[0].equals("null")) {
            return "sn";
        } else {
            //System.out.println("el que va a la ventana de venta"+foliofin);
            return (String.valueOf(dat[0]));
        }
    }

    public String idcomponente(String dato, String componente) {
        String query = "select idam_lil from am_lil where idmaquina='" + dato + "' and componente='" + componente + "'";
        System.out.println(query);
        String tipo = objCon.consultar(query, ServerBridge.getusuBD(), ServerBridge.getpasBD());
        String[] dat = tipo.split(",");
        if (dat[0].equals("") || dat[0].equals("null")) {
            return "sn";
        } else {
            //System.out.println("el que va a la ventana de venta"+foliofin);
            return (String.valueOf(dat[0]));
        }
    }

    public String cargaPuntodeinspeccion(String dato) {
        String folio = "";
        String query = "select max(punto) from am_lil where idmaquina='" + dato + "'";
        System.out.println(query);
        String tipo = objCon.consultar(query, ServerBridge.getusuBD(), ServerBridge.getpasBD());
        String[] dat = tipo.split(",");
        if (dat[0].equals("") || dat[0].equals("null")) {
            return "1";
        } else {
            int folioint = Integer.parseInt(dat[0]);
            int foliofin = folioint + 1;
            //System.out.println("el que va a la ventana de venta"+foliofin);
            return (String.valueOf(foliofin));
        }
        /*
         * String[] datf = dat[0].split("\\."); //System.out.println(datf[0]);
         * if (datf[0].equals("")) { datf[0] = "0"; }
         */


    }

    public String cargaPuntodeinspeccionComponente(String componente) {
        String folio = "";
        String query = "select max(punto) from am_lil_punto where idcomponente='" + componente + "'";
        System.out.println(query);
        String tipo = objCon.consultar(query, ServerBridge.getusuBD(), ServerBridge.getpasBD());
        String[] dat = tipo.split(",");
        if (dat[0].equals("") || dat[0].equals("null")) {
            return "1";
        } else {
            int folioint = Integer.parseInt(dat[0]);
            int foliofin = folioint + 1;
            //System.out.println("el que va a la ventana de venta"+foliofin);
            return (String.valueOf(foliofin));
        }
        /*
         * String[] datf = dat[0].split("\\."); //System.out.println(datf[0]);
         * if (datf[0].equals("")) { datf[0] = "0"; }
         */


    }

    public void cargaImagendefault(String dato) {
        String query = "select uniclave from maquinas where nombre_compuesto='" + dato + "'";
        String res = objCon.consultar(query, ServerBridge.getusuBD(), ServerBridge.getpasBD());
        String[] datosdat = res.split(",");
        CustomImageIcon foto = ConexionBaseMa.getFoto(datosdat[0]);
        ImageIcon fot = ConexionBaseMa.getFoto(datosdat[0]);
        //System.out.println(foto);
        if (fot != null) {
            Icon icono = new ImageIcon(fot.getImage().getScaledInstance(lb_foto.getWidth(), lb_foto.getHeight(), Image.SCALE_DEFAULT));

            lb_foto.setIcon(icono);
        } else {

            lb_foto.setIcon(new CustomImageIcon(getClass().getResource("/resource/defaultmedium.gif")));
        }
        lb_foto.updateUI();

    }

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        int i = JOptionPane.showConfirmDialog(this, "Desea salir", "Confirmacion", JOptionPane.YES_NO_OPTION);
        if (i == 0) {
            this.dispose();
        }
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jCheck_visualActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheck_visualActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jCheck_visualActionPerformed

    private void jChe_activaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jChe_activaMouseClicked
        if (jChe_activa.isSelected()) {
            jC_maquinasBuscar.setEnabled(true);
        } else {
            jC_maquinasBuscar.setEnabled(false);
        }// TODO add your handling code here:
    }//GEN-LAST:event_jChe_activaMouseClicked

    private void jC_maquinasBuscarItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jC_maquinasBuscarItemStateChanged
        try {
            //cargaImagendefault(String.valueOf(jC_maquinasBuscar.getSelectedItem()));
        } catch (Exception e) {
        }// TODO add your handling code here:
    }//GEN-LAST:event_jC_maquinasBuscarItemStateChanged

    public void cargaHerramientas() {
        DefaultTableModel temp1 = (DefaultTableModel) jTable_herramientas.getModel();
        //String valor=String.valueOf(jC_herramientas.getSelectedItem());
        String[] dtfa = {"EJEMPLO"};
        System.out.println(dtfa);
        String a = dtfa[0];
        temp1.addRow(dtfa);
    }

    private void jB_uplilActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_uplilActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jB_uplilActionPerformed

    private void jB_addlilActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_addlilActionPerformed
        if (jT_punto.getText().equals("") || jTA_componente.getText().equals("")
                || jTA_estandar.getText().equals("") || jTA_accion.getText().equals("")
                || jT_tiempo.getText().equals("") || validatabla().equals("1") || checkMetodo().equals("1")) {
            JOptionPane.showMessageDialog(this, "Es necesario capturar todos los campos");
        } else {
            //System.out.println("SE AGREGA LA LIL");
            System.out.println("Se agrega:" + jL_tipolil.getText());
            if (jL_tipolil.getText().equals("Componente")) {
                addlili_componente();
                limpiaLil();
                jT_punto.setText(cargaPuntodeinspeccionComponente(
                        idcomponente(idmaquina(String.valueOf(jC_maquinasBuscar.getSelectedItem())), jL_componente.getText())));

            } else {
                addlili();
                limpiaLil();
                jT_punto.setText(cargaPuntodeinspeccion(idmaquina(String.valueOf(jC_maquinasBuscar.getSelectedItem()))));
            }
        }// TODO add your handling code here:
    }//GEN-LAST:event_jB_addlilActionPerformed

    public void limpiaLil() {
        lb_foto.setIcon(new CustomImageIcon(getClass().getResource("/resource/defaultmedium.gif")));
        jC_runstop.setSelectedIndex(0);
        jL_clavelil.setText("AML_" + objDatos.getCadenaAlfanumAleatoria(8));
        jTA_componente.setText("");
        jC_categoria.setSelectedIndex(0);
        jC_prioridad.setSelectedIndex(0);
        jTA_estandar.setText("");
        jCheck_manual.setSelected(false);
        jCheck_auditivo.setSelected(false);
        jCheck_olfato.setSelected(false);
        jCheck_visual.setSelected(false);
        jC_herramientas.setSelectedIndex(0);
        limpiatablaherraminetas();
        jTA_accion.setText("");
        jT_tiempo.setText("");
        jC_frecuencia.setSelectedIndex(0);


    }

    private void lb_fotoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lb_fotoMouseClicked
        JFileChooser se = new JFileChooser();
        se.setFileSelectionMode(JFileChooser.FILES_ONLY);
        int estado = se.showOpenDialog(null);
        if (estado == JFileChooser.APPROVE_OPTION) {
            try {
                fis = new FileInputStream(se.getSelectedFile());
                //System.out.println(fis);
                this.longitudBytes = (int) se.getSelectedFile().length();
                Image icon = ImageIO.read(se.getSelectedFile()).getScaledInstance(lb_foto.getWidth(), lb_foto.getHeight(), Image.SCALE_DEFAULT);
                lb_foto.setIcon(new ImageIcon(icon));
                lb_foto.updateUI();
            } catch (FileNotFoundException ex) {
                ex.printStackTrace();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }// TODO add your handling code here:
    }//GEN-LAST:event_lb_fotoMouseClicked

    private void jC_herramientasItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jC_herramientasItemStateChanged
        if (evt.getStateChange() == ItemEvent.SELECTED) {
            if (buscapro().equals("1")) {
                try {
                    DefaultTableModel temp1 = (DefaultTableModel) jTable_herramientas.getModel();
                    Object[] dtfa = {jC_herramientas.getSelectedItem()};
                    temp1.addRow(dtfa);// TODO add your handling code here:
                } catch (Exception e) {
                }
            }else{
            JOptionPane.showMessageDialog(this,"La herramienta ya ha sido capturada");
            }
        }
    }//GEN-LAST:event_jC_herramientasItemStateChanged

    public String buscapro() {
        String regresa = "1";
        for (int x = 0; x < jTable_herramientas.getRowCount(); x++) {
            //Obtiene dato contenido en una celda de la tabla
            String value = (String) jTable_herramientas.getValueAt(x, 0);
            //System.out.println(value+"="+textcodigo.getText());
            if (value.equals(String.valueOf(jC_herramientas.getSelectedItem()))) {
                //Selecciona celda si el texto es encontrado     
                regresa = "0";
                //jTable1.changeSelection(fil, col, false, false);
            }
        }
        return regresa;
    }
    
    public void addlili_componente() {
        String queryAdd = "insert into am_lil_punto(idcomponente,runstop,punto,componente,"
                + "estandar,metodo,uniclave,accion,tiempo,frecuencia,herramientas,prioridad,status) "
                + "values(" + idcomponente(idmaquina(jL_Maquina.getText()), jL_componente.getText()) + ","
                + "'" + String.valueOf(jC_runstop.getSelectedItem()) + "',"
                + "'" + jT_punto.getText() + "',"
                + "'" + jTA_componente.getText() + "',"
                + "'" + jTA_estandar.getText() + "',"
                + "'" + cadenacheck() + "',"
                + "'" + jL_clavelil.getText() + "',"
                + "'" + jTA_accion.getText() + "',"
                + "'" + jT_tiempo.getText() + "',"
                + "'" + String.valueOf(jC_frecuencia.getSelectedItem()) + "',"
                + "'" + cadenaHerramientas() + "',"
                + "'" + String.valueOf(jC_prioridad.getSelectedItem()) + "','A')";
        System.out.println(queryAdd);
        String res = objCon.insertar(queryAdd, ServerBridge.getusuBD(), ServerBridge.getpasBD());
        if (res.equals("Exito!")) {
            JOptionPane.showMessageDialog(this, "Se agrego correctamente la LIL del componente: " + jL_componente.getText());
            limpiaLil();
        } else {
            JOptionPane.showMessageDialog(this, "Ocurrio un error a la hora de generar la LIL: " + res);
        }
    }

    public void addlili() {
        String queryAdd = "insert into am_lil(idmaquina,runstop,punto,componente,"
                + "estandar,metodo,uniclave,accion,tiempo,frecuencia,herramientas,categoria,prioridad,status) "
                + "values(" + idmaquina(String.valueOf(jC_maquinasBuscar.getSelectedItem())) + ","
                + "'" + String.valueOf(jC_runstop.getSelectedItem()) + "',"
                + "'" + jT_punto.getText() + "',"
                + "'" + jTA_componente.getText() + "',"
                + "'" + jTA_estandar.getText() + "',"
                + "'" + cadenacheck() + "',"
                + "'" + jL_clavelil.getText() + "',"
                + "'" + jTA_accion.getText() + "',"
                + "'" + jT_tiempo.getText() + "',"
                + "'" + String.valueOf(jC_frecuencia.getSelectedItem()) + "',"
                + "'" + cadenaHerramientas() + "',"
                + "'" + String.valueOf(jC_categoria.getSelectedItem()) + "',"
                + "'" + String.valueOf(jC_prioridad.getSelectedItem()) + "','A')";
        System.out.println(queryAdd);
        String res = objCon.insertar(queryAdd, ServerBridge.getusuBD(), ServerBridge.getpasBD());
        if (res.equals("Exito!")) {
            Maquina cl1 = new Maquina();
            cl1.setNombre(jL_clavelil.getText());
            cl1.setFoto(fis);

            //System.out.println(fis);
            //System.out.println(cl);
            //System.out.println(ControllerMaquina.class);
            System.out.println(cl1);
            int opcion = cc1.insertMaquinalil(cl1);
            System.out.println(opcion);
            if (opcion != 0) {
                try {
                    //JOptionPane.showMessageDialog(this, "Registro "+cl+" agregado");
                    System.out.println("Registro " + cl1 + " Agregado");
                    if (fis != null) {
                        fis.close();
                    }
                    fis = null;
                } catch (IOException ex) {
                    Logger.getLogger(InterMaquinas.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            JOptionPane.showMessageDialog(this, "Se agrego correctamente la LIL");
        } else {
            JOptionPane.showMessageDialog(this, "Ocurrio un error a la hora de generar la LIL: " + res);
        }
    }

    public String cadenaHerramientas() {
        DefaultTableModel temp1 = (DefaultTableModel) jTable_herramientas.getModel();
        String cadHer = "";
        for (int x = 0; x < temp1.getRowCount(); x++) {
            String herramineta = String.valueOf(this.jTable_herramientas.getValueAt(x, 0));
            cadHer = cadHer + "%" + herramineta;
        }
        return cadHer;
    }

    public String idmaquina1(String dato) {
        String query = "select idmaquinas from maquinas where nombre_compuesto='" + dato + "'";
        String res = objCon.consultar(query, ServerBridge.getusuBD(), ServerBridge.getpasBD());
        String[] datosdat = res.split(",");
        if (datosdat[0].equals("")) {
            return "1";
        } else {
            System.out.println("Id maquina: " + datosdat[0]);
            return datosdat[0];
        }
    }

    public String validatabla() {
        DefaultTableModel temp1 = (DefaultTableModel) jTable_herramientas.getModel();
        int a = temp1.getRowCount();
        String v = "0";
        if (a == 0) {
            return "1";
        } else {
            return "0";
        }
    }

    public String checkMetodo() {
        if (jCheck_manual.isSelected() && jCheck_auditivo.isSelected()
                && jCheck_olfato.isSelected() && jCheck_visual.isSelected()) {
            return "1";
        } else {
            return "0";
        }
    }

    public String cadenacheck() {
        String a = "00";
        String b = "00";
        String c = "00";
        String d = "00";
        if (jCheck_auditivo.isSelected()) {
            a = "01";
        }
        if (jCheck_manual.isSelected()) {
            b = "01";
        }
        if (jCheck_olfato.isSelected()) {
            c = "01";
        }
        if (jCheck_visual.isSelected()) {
            d = "01";
        }
        System.out.println(a + "@" + b + "@" + c + "@" + d);
        return a + "@" + b + "@" + c + "@" + d;

    }

    private void llenarCombomaquinas() {
        String query = "select nombre_compuesto from maquinas where status='A' order by nombre";
        String res = objCon.consultar(query, ServerBridge.getusuBD(), ServerBridge.getpasBD());
        if (res.length() > 0) {
            String arr[] = res.split(",");
            jC_maquinasBuscar.setModel(new javax.swing.DefaultComboBoxModel(arr));

        } else //this.dispose();
        //new configura().setVisible(true);
        //JOptionPane.showMessageDialog(null,"Error de conectividad");
        {

            jC_maquinasBuscar.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"Agregue algun campo"}));
        }

        //jCusuarios.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Agregue algun campo"}));
    }
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jB_addlil;
    private javax.swing.JButton jB_cleanlil;
    private javax.swing.JButton jB_dellil;
    private javax.swing.JButton jB_uplil;
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jC_categoria;
    private javax.swing.JComboBox jC_frecuencia;
    private javax.swing.JComboBox jC_herramientas;
    private javax.swing.JComboBox jC_maquinasBuscar;
    private javax.swing.JComboBox jC_prioridad;
    private javax.swing.JComboBox jC_runstop;
    private javax.swing.JCheckBox jChe_activa;
    private javax.swing.JCheckBox jCheck_auditivo;
    private javax.swing.JCheckBox jCheck_manual;
    private javax.swing.JCheckBox jCheck_olfato;
    private javax.swing.JCheckBox jCheck_visual;
    private javax.swing.JLabel jL_Maquina;
    private javax.swing.JLabel jL_clavelil;
    private javax.swing.JLabel jL_componente;
    private javax.swing.JLabel jL_fecha;
    private javax.swing.JLabel jL_tipolil;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTextArea jTA_accion;
    private javax.swing.JTextField jTA_componente;
    private javax.swing.JTextArea jTA_estandar;
    private javax.swing.JTextField jT_punto;
    private javax.swing.JTextField jT_tiempo;
    private javax.swing.JTable jTable_herramientas;
    private javax.swing.JLabel lb_foto;
    // End of variables declaration//GEN-END:variables
}
